package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageResult;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 渣哥
 * @CreateTime: 2025/5/28  16:17
 * @Description:
 */

@Service
public class EmpServiceImpl implements EmpService {
   @Autowired
    private EmpMapper empMapper;

   //-----------------------------原始分页查询-------------------------
//    @Override
//    public PageResult page(Integer page, Integer pageSize) {
//       //1.查询总记录数
//        Long total = empMapper.count();
//        //2.查询当前页数据
//     Integer start=(page-1)*pageSize;
//        List<Emp> empList = empMapper.list(start, pageSize);
////3.封装PageResult对象
//        return new PageResult<Emp>(empList,total);
//    }
    @Override
    public PageResult page(Integer page, Integer pageSize) {
        //1.设置分页参数（PageHelper）
        PageHelper.startPage(page,pageSize);

        //2.执行查询
        List<Emp> empList = empMapper.list();

        //解析查询结果，并封装
        Page<Emp> p = (Page<Emp>) empList;
        return new PageResult<Emp>(p.getResult(),p.getTotal());
    }



}
